<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加活动</title>
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/index.css">
    <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/index.js"></script>
    <script type="text/javascript" src="/static/js/jquery.js"></script>


</head>
<body>

<div class="layui-card">
    <form class="layui-form layui-form-pane" action="" id="add">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <ul class="layui-tab-title">
                <li class="layui-this">基本信息</li>
            </ul>

            <input type="hidden" id="id" th:value="${activity?.activityId}">
            <div class="layui-tab-content" >
                <div class="layui-tab-item layui-show">
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>活动主题
                        </label>
                        <div class="layui-input-block">
                            <input type="text"   autocomplete="off" id="activityTitle" placeholder="活动主题"
                                   class="layui-input"  th:value="${activity?.activityTitle}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>开始日期
                        </label>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" type="date"  autocomplete="off" placeholder="开始日" id="start" th:value="${activity?.activityStartTime}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>结束日期
                        </label>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" type="date"  autocomplete="off" placeholder="结束日" id="end" th:value="${activity?.activityEndTime}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>活动地点
                        </label>
                        <div class="layui-input-block">
                            <input type="text" id="activityAddress" autocomplete="off" placeholder="活动地点" th:value="${activity?.activityAddress}"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>活动人数
                        </label>
                        <div class="layui-input-block">
                            <input type="text" id="activityNumber" autocomplete="off" placeholder="每次最多1000人" th:value="${activity?.activityNumber}"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>活动费用
                        </label>
                        <div class="layui-input-block">
                            <input type="text" id="activityFee" autocomplete="off" placeholder="每次最多1万元" th:value="${activity?.activityFee}"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item  layui-form-text">
                        <label  class="layui-form-label">
                            <span class="x-red">*</span>活动内容
                        </label>
                        <div class="layui-input-block">
                            <textarea   id="content"  class="layui-textarea" th:text="${activity?.activityContent}"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <button class="layui-btn" type="button" lay-filter="add" lay-submit="" onclick="add()">
                            保存
                        </button>
                    </div>
                    <!--</form>-->
                    <div style="height:100px;"></div>
                </div>
            </div>

        </div>
    </form>
</div>

<script type="text/javascript">
    $(function(){
        //得到当前时间
        var date_now = new Date();
        //得到当前年份
        var year = date_now.getFullYear();
        //得到当前月份
        //注：
        //  1：js中获取Date中的month时，会比当前月份少一个月，所以这里需要先加一
        //  2: 判断当前月份是否小于10，如果小于，那么就在月份的前面加一个 '0' ， 如果大于，就显示当前月份
        var month = date_now.getMonth()+1 < 10 ? "0"+(date_now.getMonth()+1) : (date_now.getMonth()+1);
        //得到当前日子（多少号）
        var date = date_now.getDate() < 10 ? "0"+date_now.getDate() : date_now.getDate();
        //设置input标签的min属性
        $("#start").attr("min",year+"-"+month+"-"+date);
        $("#end").attr("min",year+"-"+month+"-"+date);
    })
    $("#start").blur(function(){
        var starttime = $("#start").val();
        $("#end").val(starttime);
        $("#end").attr("min",starttime);
    });

    function add() {
        var start= $("#start").val();
        var end= $("#end").val();
        var activityTitle = $("#activityTitle").val();
        var activityAddress = $("#activityAddress").val();
        var activityNumber = $("#activityNumber").val();
        var activityFee = $("#activityFee").val();
        var content = $("#content").val();
        var id = $("#id").val();
        if (activityNumber>1000||activityFee>10000) {
            alert("填写信息错误，请重新填写")
        }else {
            $.ajax({
                url: 'updateActivity',
                method: 'post',
                async: false,
                data: {
                    'activityId': id,
                    'activityTitle': activityTitle,
                    'activityAddress': activityAddress,
                    'activityNumber': activityNumber,
                    'activitySpare': activityNumber,
                    'activityFee': activityFee,
                    'activityStartTime':start,
                    'activityEndTime':end,
                    'activityContent':content
                },
                success: function (data) {
                    res = data;
                }
            });
            if (res == "1") {
                location.reload();
            } else {
                window.location.href = "toErrorPage"
            }
        }

    }
</script>
</body>
</html>